<html>
<head>
<meta charset="UTF-8">
<title>业务系统列表</title>
<link id="easyuiTheme" href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<link href="../../static/easyui/themes/frameless.css" rel="stylesheet" type="text/css"/>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<script type="text/javascript">

    var roleno;
	function doAdd(){
		JLEUtil.createModalWin('新增', 'SSubsInfoAdd.html');
	}
	
	function doUpdate() {
		var row = $('#dg').datagrid('getSelected');
		if (row){
			JLEUtil.createModalWin('修改', 'SSubsInfoUpdate.html?' + 'subsCode=' + row.subsCode);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}
	
	function doDelete(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$.messager.confirm('删除提示', '你确定要删除这条记录?', function(r){
				if (r){
					var jsonData = JSON.parse('{'+'"subsCode":"' + row.subsCode + '"'+'}');
					$.restfulDelete('../../api/s/subs/info', jsonData, function(data) {
						$.messager.alert('提示','记录删除成功!','info');
						$('#dg').datagrid('reload');
					});
				}
			});
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function doView(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			JLEUtil.createModalWin('详情','SSubsInfoView.html?' + '&subsCode=' + row.subsCode);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}
    function getRolesNumber(){
        $.ajax({
            type: "POST",
            url: '../../api/s/roles',
            data: {
            },
            success: function(data) {
                roleno=data.rows[0].roleno;
            }
        });
    }
    //创建业务系统根菜单
    function createRootNode() {
        var row = $('#dg').datagrid('getSelected');
        //判断业务系统是否已创建根节点
        $.restfulGet('../../api/s/resource/' + row.subsCode,
            null,
            function(data){
                $.messager.alert('提示','业务系统已是根节点，请勿重复创建','info');
            },
            function (data) {
                var jsonData={
                    resourceid:row.subsCode,
                    cnname:row.subsName,
                    systempk:row.subsCode,
                    parentid:'root',
					orderid:row.orderId
                };
                $.restfulPostJson('../../api/s/resource', jsonData, function(data) {
                    //资源定义
                    var actionJsondate=JSON.parse('{'+'"descr":"' + '菜单访问' + '"'
                        + ','+'"resourceid":"' + jsonData.resourceid + '"'
                        + ','+'"actid":"' + 'visit' + '"'+'}');
                    $.restfulPostJson('../../api/s/resourceaction', actionJsondate, function(data) {
                    });
                    //资源操作
                    var roleJsondate=JSON.parse('{'+'"roleno":"' + roleno + '"'
                        + ','+'"resourceid":"' + jsonData.resourceid + '"'
                        + ','+'"actIdStr":"' + 'visit' + '"'+'}');
                    console.log("roleno="+roleno);
                    $.restfulPostJson('../../api/s/role/right/save', roleJsondate, function(data) {
                    });

                });
                $.messager.alert('提示','创建根节点成功！','info');
                // $.messager.confirm('跳转提示', '是否要跳转到?', function(r){
                //     if (r){
                //         // $('#tt').tabs('enableTab', '自动流程配置');
                //         addTab("自动流程配置","AutoBpmBaseInfoList.html")
                //     }
                // });
            });
    }

	//创建业务系统流程配置菜单
	function createDevopsMenu() {
		var row = $('#dg').datagrid('getSelected');
		//判断是否选择一条记录
		if (row){
			//判断业务系统是否是根节点，否则要先创建为根节点
			var row = $('#dg').datagrid('getSelected');
			var jsonData={
				resourceid:row.subsCode+"-system",
				cnname:row.subsName,
				url:'devops-console/DevopsIndex.html?subsCode='+row.subsCode,
				orderid:row.orderId,
				systempk:'mp',
				parentid:'devopsbpa',
			};
			//判断业务系统是否存在流程配置菜单
			$.restfulGet('../../api/s/resource/' + jsonData.resourceid,
					null,
					function(data){//已存在则提示请勿重复创建
						$.messager.alert('提示','业务系统流程配置菜单已创建，请勿重复创建！','info');
					},
					function(){//查询不存在则创建
						$.restfulPostJson('../../api/s/resource', jsonData, function(data) {
							//资源定义
							var actionJsondate=JSON.parse('{'+'"descr":"' + '菜单访问' + '"'
									+ ','+'"resourceid":"' + jsonData.resourceid + '"'
									+ ','+'"actid":"' + 'visit' + '"'+'}');
							$.restfulPostJson('../../api/s/resourceaction', actionJsondate, function(data) {
							});
							//资源操作
							var roleJsondate=JSON.parse('{'+'"roleno":"' + roleno + '"'
									+ ','+'"resourceid":"' + jsonData.resourceid + '"'
									+ ','+'"actIdStr":"' + 'visit' + '"'+'}');
							$.restfulPostJson('../../api/s/role/right/save', roleJsondate, function(data) {
							});
						});
						$.messager.alert('提示','流程配置菜单创建成功！','info');
					});
		}else{
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}


    //创建业务系统流程配置菜单
    function createProcessConf() {
        var row = $('#dg').datagrid('getSelected');
        //判断是否选择一条记录
        if (row){
            //判断业务系统是否是根节点，否则要先创建为根节点
            $.restfulGet('../../api/s/resource/' + row.subsCode,
                null,
                function(data){
                    var row = $('#dg').datagrid('getSelected');
                    var jsonData={
                        resourceid:row.subsCode+"bpa",
                        cnname:"流程配置",
                        systempk:row.subsCode,
                        parentid:row.subsCode,
                    };
                    //判断业务系统是否存在流程配置菜单
                    $.restfulGet('../../api/s/resource/' + jsonData.resourceid,
                        null,
                        function(data){//已存在则提示请勿重复创建
                            $.messager.alert('提示','业务系统流程配置菜单已创建，请勿重复创建！','info');
                        },
                        function(){//查询不存在则创建
                            $.restfulPostJson('../../api/s/resource', jsonData, function(data) {
                                //资源定义
                                var actionJsondate=JSON.parse('{'+'"descr":"' + '菜单访问' + '"'
                                    + ','+'"resourceid":"' + jsonData.resourceid + '"'
                                    + ','+'"actid":"' + 'visit' + '"'+'}');
                                $.restfulPostJson('../../api/s/resourceaction', actionJsondate, function(data) {
                                });
                                //资源操作
                                var roleJsondate=JSON.parse('{'+'"roleno":"' + roleno + '"'
                                    + ','+'"resourceid":"' + jsonData.resourceid + '"'
                                    + ','+'"actIdStr":"' + 'visit' + '"'+'}');
                                $.restfulPostJson('../../api/s/role/right/save', roleJsondate, function(data) {
                                });
                            });
                            $.messager.alert('提示','流程配置菜单创建成功！','info');
                        });
                },
                function (data) {
                    $.messager.alert('提示','业务系统还不是根节点，请先创建根节点','info');
                });
        }else{
            $.messager.alert('提示','请选择一条记录！','info');
        }
    }

    function changeSystemCode(){
		if (!$('#ff').form('validate')){
			return;
		}else {
			var jsonData = $("#ff").serializeJson();
			//将相关表的所属业务系统变更为新的业务系统代码
			$.restfulPut('../../api/s/subs/info/chang/subs/code', jsonData, function(data) {
				$.restfulPut('../../api/s/resource/change/url/subs/code',jsonData,function (data){});
				$.restfulPut('../../api/bat/batch/info/change/subs/code',jsonData,function (data){});
				$.restfulPut('../../api/bat/inst/batch/change/subs/code',jsonData,function (data){});
				$.restfulPut('../../api/bat/inst/batch/h/change/subs/code',jsonData,function (data){});
				$.restfulPut('../../api/s/srvs/cron/conf/change/subs/code',jsonData,function (data){});
				$.restfulPut('../../api/s/subs/datasource/change/subs/code',jsonData,function (data){});
				$.restfulPut('../../api/dbo/backup/conf/change/subs/code',jsonData,function (data){});
				$.restfulPut('../../api/sys/apps/info/change/subs/code',jsonData,function (data){});
				$.restfulPut('../../api/sys/deploy/info/change/subs/code',jsonData,function (data){});
				$.restfulPut('../../api/sys/ecs/info/change/subs/code',jsonData,function (data){});
				$.restfulPut('../../api//bpm/base/info/change/subs/code',jsonData,function (data){});
				$('#dg').datagrid('reload');
				closeDialog();
			});
		}



	}

	function openDialog(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$("#dd").window('open')
			$("#oldSubsCode").textbox('setValue',row.subsCode)
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function closeDialog(){
		$("#dd").window('close')
	}

	function reloadList(){
		$('#dg').datagrid('reload');
		JLEUtil.closewin();
	};
    $(function () {
        //获取角色列表
        getRolesNumber();
    })
</script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',title:''" style="height: 40px; ">
	<form id="searchForm">
		<table>
			<tr>
				<td class="searchTd">&nbsp;业务系统代码：</td>
				<td><input name="subsCode" id="subsCode"/></td>
				<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="JLEUtil.queryForm('searchForm','dg','../../api/s/subs/infos');">查找</a></td>
				<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="JLEUtil.clearForm('searchForm');">清空</a></td>
			</tr>
		</table>
	</form>
</div>
<div data-options="region:'center',split:false">
<table id="dg" class="easyui-datagrid" title="" style="width:100%;height:94%"
			data-options="singleSelect:true,collapsible:true,url:'../../api/s/subs/infos',method:'post'"
			toolbar="#tb"
		title="Load Data" 
		rownumbers="true" pagination="true" pageSize="20">
		<thead>
			<tr>
				<th data-options="field:'subsCode',resizable:true" >业务系统代码</th>
				<th data-options="field:'subsName',resizable:true" >业务系统名称</th>
				<th data-options="field:'subsDataDate',resizable:true" >业务系统数据日期</th>
				<th data-options="field:'subsLastDataDate',resizable:true" >业务系统上一数据日期</th>
				<th data-options="field:'subsLoadDate',resizable:true" >业务系统装数完成日期</th>
				<th data-options="field:'subsBatDate',resizable:true" >业务系统批次完成日期</th>
				<th data-options="field:'batchIdPrefix',resizable:true" >流程编号前缀</th>
				<th data-options="field:'rsvDate',resizable:true" >备用日期</th>
				<th data-options="field:'rsvState',resizable:true" >备用状态</th>
				<th data-options="field:'orderId',resizable:true" >排序字段</th>
			</tr>
		</thead>
	</table>
</div>
<div id="tb" style="padding:1px">
	<div style="margin-bottom:2px">
		<a href="javascript:doAdd()" class="easyui-linkbutton" iconCls="icon-add" plain="true">新增</a>
		<a href="javascript:doUpdate()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
		<a href="javascript:doDelete()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
		<a href="javascript:doView()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">查看</a>
		<a href="javascript:createRootNode()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">创建业务系统根菜单</a>
		<a href="javascript:createDevopsMenu()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">创建业务系统devops菜单</a>
		<a href="javascript:openDialog()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">变更业务系统代码</a>
	</div>
</div>
<div id="dd"  class="easyui-dialog" title="变更业务系统代码" style="width:400px;height:200px;" data-options="closed:true,resizable:true,modal:true">
	<form id="ff" method="post">
		<table class="esaas-info-edit-table">
			<tr>
				<td width="40%" align="right">原业务系统代码：</td>
				<td width="60%"><input id="oldSubsCode" class="easyui-textbox" type="text" disabled
									   name="oldSubsCode" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="40%" align="right">新业务系统代码：</td>
				<td width="60%"><input id="newSubsCode" class="easyui-textbox" type="text"
									   name="newSubsCode" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
		</table>
	</form>
	<div style="text-align: center; padding: 15px">
		<a href="javascript:void(0)" class="easyui-linkbutton"
		   onclick="changeSystemCode()">&nbsp;保&nbsp;存&nbsp;</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			onclick="closeDialog()">&nbsp;关&nbsp;闭&nbsp;</a>
	</div>

</div>
</body>
</html>
